package com.wnnight.wys.serviceImpl.config;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wnnight.wys.entity.PageBean;
import com.wnnight.wys.entity.config.PropertyStaff;
import com.wnnight.wys.mapper.config.PropertyStaffMapper;
import com.wnnight.wys.mapper.config.propertyAreaMapper;
import com.wnnight.wys.service.config.PropertyStaffService;
import com.wnnight.wys.util.config.MyBatisUtil;
import com.wnnight.wys.vo.config.PropertyStaffVo;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName: PropertyStaffImpl
 * @Description: //TODO
 * @author: LZJ
 * @date: 2022/8/28-12:29
 * @version: v1.0
 */
@Service("propertyStaffService")
@Transactional
public class PropertyStaffImpl extends ServiceImpl<PropertyStaffMapper, PropertyStaff> implements PropertyStaffService {
    @Resource
    private PropertyStaffMapper propertyStaffMapper;
    @Resource
    private propertyAreaMapper propertyAreaMapper;

    @Override
    public void add(PropertyStaff propertyStaff, int[] palceIds) {
        System.out.println(propertyStaff.getId());
        propertyStaff.setUpdateTime(MyBatisUtil.getNowTime());
        propertyStaffMapper.add(propertyStaff);
        System.out.println(propertyStaff.getId());
        for (int palceId : palceIds) {
            propertyAreaMapper.add(propertyStaff.getId(), palceId);
        }
    }

    @Override
    public void update(PropertyStaff propertyStaff, int[] palceIds) {
        propertyStaffMapper.update(propertyStaff);
        propertyAreaMapper.delete(propertyStaff.getId());
        for (int palceId : palceIds) {
            propertyAreaMapper.add(propertyStaff.getId(), palceId);
        }
    }

    @Override
    public IPage<PropertyStaff> getAll(IPage<PropertyStaff> page,QueryWrapper<PropertyStaff> queryWrapper) {
        return propertyStaffMapper.getAll(page,queryWrapper);
    }


    //查询权限
    @Override
    public PropertyStaff getMenuById(int id) {
        return propertyStaffMapper.getMenuById(id);
    }

    @Override
    public PropertyStaff getByAccountAndPassword(String account, String password) {
        return propertyStaffMapper.getByAccountAndPassword(account, password);
    }

    @Override
    public PropertyStaff getByAccount(String account) {
        return propertyStaffMapper.getByAccount(account);
    }

    @Override
    public PropertyStaff getById(int id) {
        return propertyStaffMapper.getById(id);
    }

    @Override
    public void updatePsd(int id, String password) {
        PasswordEncoder encoder = new BCryptPasswordEncoder();
        propertyStaffMapper.updatePsd(id, encoder.encode(password));
    }

    @Override
    public PropertyStaff getStaffByPlaceId(int placeId) {
        return propertyStaffMapper.getStaffByPlaceId(placeId);
    }

    @Override
    public List<PropertyStaff> getImg() {
        return propertyStaffMapper.getImg();
    }
}
